<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%
    String srcUid = token.getUid()+"";
    String destUid = input.getDesc("dest_uid", "");
    String content = input.getDesc("content", "");
    if ("".equals(destUid) || srcUid.equals(destUid)) {
        msg = new Message(30071, "好友请求不合法");
        Tools.encryptPrint(out, msg);
        return;
    }
    List result = new ArrayList();
    List list = QBuilder.db("basedb").select().from("friend").where(new Where("src_uid =", srcUid).and("dest_uid = ",destUid).and("status = ", STATUS_ENABLE).and("state != 2")).query().getResultObj();
    result.addAll(list);
    list = QBuilder.db("basedb").select().from("friend").where(new Where("src_uid =", destUid).and("dest_uid = ",destUid).and("status = ", STATUS_ENABLE).and("state != 2")).query().getResultObj();
    result.addAll(list);
    if (isEmpty(result)) {
        Map map = new HashMap();
        map.put("src_uid", srcUid);
        map.put("dest_uid", destUid);
        map.put("state", 0);
        map.put("content", content);
        map.put("status", STATUS_ENABLE);
        map.put("create_time", new Date().getTime());
        Integer id = (Integer)DBTools.db("basedb").addItem("friend", map);
        if (isEmpty(id)) {
            msg = new Message(30071, "好友请求失败");
            Tools.encryptPrint(out, msg);
            return;
        }
        msg.put("data", id);
    }
    Tools.encryptPrint(out, msg);
%>
